﻿using System.Reflection;
using System.Web.Mvc;
using System.Web.Routing;
using Domain;
using Microsoft.Practices.Unity;
using WebUI.Properties;

namespace WebUI
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "Default",                                         // Route name
                "{controller}/{action}",                           // URL with parameters
                new { controller = "Contact", action = "Index" }   // Parameter defaults
            );

        }

        /// <summary>
        /// In case you want to access the container from the current HttpApplication.
        /// </summary>
        public static IUnityContainer Container { get; private set; }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            RegisterRoutes(RouteTable.Routes);
            Container = new UnityContainer();

            var containerName = Settings.Default.Unity_Container_Name;

            //Configure using web.config file, assuming the section is named "Unity".
            MvcUnity.Bootstrapper.Run(Container, Assembly.GetExecutingAssembly(), null, containerName);

            //Configure using a single configuration file in the root "unity.config".
            //MvcUnity.Bootstrapper.Run(Container, Assembly.GetExecutingAssembly(), Server.MapPath("~/unity.config"), containerName);

            //Configure using multiple configuration files for a single container.
            //MvcUnity.Bootstrapper.LoadConfig(Container, Server.MapPath("~/unity.config"));
            //MvcUnity.Bootstrapper.LoadConfig(Container, Server.MapPath("~/unityExtended.config"));
            //MvcUnity.Bootstrapper.Run(Container, Assembly.GetExecutingAssembly());

            //or configured in code
            //Container.RegisterType<IRepository, XmlDomain.Repository>(new MvcUnity.HttpContextLifetimeManager());
            //Container.RegisterType<IContact, XmlDomain.Contact>();
            //MvcUnity.BootStrapper.Run(Container);

        }
    }
}